package ru.gosoplata.service.conn 
{
	import ru.gosoplata.model.TmpModel;
	/**
	 * ...
	 * @author 
	 */
	public class CammandsStack 
	{
		private var _length:uint = 0;
		private var _stack:Array = new Array();
		
		public function CammandsStack() 
		{
			
		}
		
		public function push(command:Command):void 
		{
			_length++;
			if (!_stack[command.priority])_stack[command.priority] = new Array();
			(_stack[command.priority] as Array).push(command);
		}
		
		public function shift():Command 
		{
			var ar:Array;
			var command:Command;
			for each (ar in _stack) 
			{
				command = ar.shift();
				_length--;
				if (ar.length==0) {
					delete _stack[command.priority];
				}
				//TmpModel.debugOutput.add('shift ' + _length + " " + command.priority + " " + JSON.stringify(_stack));
				break;
			}
			return command;
		}
		
		public function get length():uint 
		{
			return _length
		}
	}

}